


$(function(){

$('#bussinessDiv').hide();
$('#container_loginType').buttonset();
                     $(".loginButton").button();
                     $('.errorMessageDiv').hide();

                      var loginName = jQuery(':input[id=loginName]');
                      var loginPassword = jQuery(':input[id=loginPassword]');

           // var userTypeButton = jQuery(':input[name=userType]');


            $('#container_userType').buttonset();
            //jQuery('.ui-button-text').css('width','250px');

var loginHiddenResponseDiv = jQuery('#loginResponseDiv');
loginHiddenResponseDiv.hide();
        var allFields = jQuery([]).add(loginName).add(loginPassword);

     $(".loginButton").click(function(){
 var bValid = true;
 allFields.removeClass('ui-state-error');

bValid = bValid && formValidator.checkIfEmpty(loginName);
 bValid = bValid && formValidator.checkRegexp(loginName,/^([0-9a-zA-Z])+$/,"Only alphanumeric characters allowed (a-z 0-9).");
 bValid = bValid && formValidator.checkIfEmpty(loginPassword);
 bValid = bValid && formValidator.checkRegexp(loginPassword,/^([0-9a-zA-Z])+$/,"Only alphanumeric characters allowed (a-z 0-9).");

    if (bValid) {
sendRequest.setAction('loginUser');
var loginType1 = $("input:radio[name=loginType]:checked").val();
loginData = {'loginName':loginName.val(),'loginPassword':loginPassword.val(),'loginType':loginType1};
sendRequest.setSendParameters(loginData);
loginHiddenResponseDiv.load(sendRequest.serverURL, sendRequest.getSendData(), function(){
loginHiddenResponseDiv.unbind();
//if (loginHiddenResponseDiv.html() == '1')
//    {
//   sendRequest.setAction('business');
//               sendRequest.setSendParameters(null);
//               $('#adminDiv').load(sendRequest.serverURL, sendRequest.getSendData(), function(){
////options = { percent: 0 };
////
//////$('#homeDiv').effect('blind','',2000 ).empty();
//$('#homeDiv').hide('slow');
//   $('#adminDiv').show();
//               });
       if (loginType1 == 'business')
           {

               sendRequest.setAction('businessHome');
               sendRequest.setSendParameters(null);
               $('#businessDiv').load(sendRequest.serverURL, sendRequest.getSendData(), function(){

$('#homeDiv').hide('slow');
   $('#businessDiv').show();
               });
           }
           else
               {
                    sendRequest.setAction('customerHome');
               sendRequest.setSendParameters(null);
               $('#customerDiv').load(sendRequest.serverURL, sendRequest.getSendData(), function(){
$('#homeDiv').hide('slow');
   $('#customerDiv').show();
               });
               }
/*    }
    else if  (loginHiddenResponseDiv.html() == '2')
        {
               sendRequest.setAction('adminHome');
               sendRequest.setSendParameters(null);
               $('#adminDiv').load(sendRequest.serverURL, sendRequest.getSendData(), function(){

$('#homeDiv').hide('slow');
   $('#adminDiv').show();
               });
        }
    else
        {
            formValidator.updateErrorMessage("User does not exist.");
        }*/

});
}
     });

if(typeof runHomeTests == 'function') {
$('#homeDiv').prepend("<h3>Running Home Tests</h3><div id ='testViewer'></div>");
runHomeTests();
}


});